/*
 * Main.java
 *
 * Created on May 9, 2007, 9:53 PM
 *
 * 
 */

package diversion.v1;

//~--- JDK imports ------------------------------------------------------------

import java.lang.reflect.InvocationTargetException;

/**
 * Main class is used to launch any class contained
 * within the Diversion jar file that contains a main([])
 * method.
 * @author Joel
 */
public class Main {

    /** Creates a new instance of Main */
    public Main() {}

    public static void showClasses() {
        
        System.out.println("diversion.v1.network.Server");
        System.out.println("diversion.v1.ui.Client");
        
    }
    /**
     * Main method
     * @param args command line arguments
     */
    public static void main(String[] args) {
        String classToLoad = "";

        if (args.length > 0) {
            classToLoad = args[0];
        } else {
            showClasses();
            System.exit(0);
        }
        
        if (classToLoad.equals(Main.class.getCanonicalName())) {
            showClasses();
            System.exit(0);
        }

        try {
            ClassLoader.getSystemClassLoader().loadClass(classToLoad).getMethod("main",
                    new Class[] { String[].class }).invoke(null, new Object[] { args });
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            showClasses();
        } catch (ClassNotFoundException e) {
            showClasses();
        }
    }
}

